package com.cc.self.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cc.self.dao.SelfBusDao;
import com.cc.self.model.raw.SelfBus;


@Service(value = "com.cc.self.service.SelfBusService")
public class SelfBusService {
	@Autowired
	private SelfBusDao aSelfBusDao;

	public int getSelfBusCount(String code, String wx_no, String gs_no, String customer, String bdt, String edt, String bg_no, Integer status, String ywy) {
		Map<String,Object> p = new HashMap<String,Object>();
		p.put("code", code);
		p.put("wx_no", wx_no);
		p.put("gs_no", gs_no);
		p.put("customer", customer);
		p.put("bdt", bdt);
		p.put("edt", edt);
		p.put("bg_no", bg_no);
		p.put("status", status);
		p.put("ywy", ywy);
		
		return aSelfBusDao.getSelfBusCount();
	}
	/**
	 * 根据组织查询列表
	 * @param ono 组织代码
	 * @return List<SelfBus>
	 */
	public List<SelfBus> getSelfBusList(String code, String wx_no, String gs_no, String customer, String bdt, String edt, String bg_no, Integer status, String ywy, Integer start, Integer limit) {
		Map<String,Object> p = new HashMap<String,Object>();
		p.put("code", code);
		p.put("wx_no", wx_no);
		p.put("gs_no", gs_no);
		p.put("customer", customer);
		p.put("bdt", bdt);
		p.put("edt", edt);
		p.put("bg_no", bg_no);
		p.put("status", status);
		p.put("ywy", ywy);
		p.put("start", start);
		p.put("limit", limit);
		List<SelfBus> list = aSelfBusDao.getSelfBusList(p);
		return list;
	}

	/**
	 * 获取实体
	 * @param id 主键
	 * @return SelfBus
	 */
	public SelfBus getSelfBus(int id) {
		Map<String, Object> p = new HashMap<String, Object>();
		p.put("id", id);
		List<SelfBus> l = aSelfBusDao.getSelfBusList(p);
		return l.size() > 0 ? l.get(0) : null;
	}

	/**
	 * 创建实体
	 * @param SelfBus 实体信息
	 * @return SelfBus 实体信息
	 */
	public SelfBus createSelfBus(SelfBus entity) {
		aSelfBusDao.createSelfBus(entity);
		return entity;
	}
	
	/**
	 * 修改实体
	 * @param SelfBus 实体信息
	 * @return SelfBus 实体信息
	 */
	public SelfBus updateSelfBus(SelfBus entity) {
		aSelfBusDao.updateSelfBus(entity);
		return entity;
	}
	
	/**
	 * 删除实体
	 * @param SelfBus 实体信息
	 * @return SelfBus 实体信息
	 */
	public SelfBus deleteSelfBus(SelfBus entity) {
		deleteSelfBus(entity.getId());
		return entity;
	}
	
	/**
	 * 删除实体
	 * @param id 主键
	 * @return id 主键
	 */
	public int deleteSelfBus(int id) {
		aSelfBusDao.deleteSelfBus(id);
		return id;
	}
	
	/**
	 * 改变状态
	 * @param id int 自营主键
	 * @param status 自营记录状态
	 */
	public int updateSelfBusStatus(int id, int status) {
		Map<String,Object> p = new HashMap<String,Object>();
		p.put("id", id);
		p.put("status", status);
		aSelfBusDao.updateSelfBusStatus(p);
		return status;
	}

}

